<template>
  <div class="app-container">
    <el-form :inline="true" class="demo-form-inline">
      <el-form-item>
        <el-input v-model="contractId" placeholder="合约id" />
      </el-form-item>
      <el-button type="primary" icon="el-icon-search" @click="findContractTxIdListById()">合约id查询</el-button>
    </el-form>

    <!-- banner列表 -->
    <el-table :data="list" stripe style="width: 100%">
      <el-table-column type="index" width="50" label="序号" />
      <el-table-column prop="TxId" label="交易id" />
    </el-table>
  </div>
</template>

<script>
import chain from '@/api/chain'

export default {
  // 定义变量和初始值
  data() {
    return {
      contractId: '',
      list: []
    }
  },
  created() {
  },
  methods: {
    findContractTxIdListById() {
      chain
        .findContractTxIdListById(this.contractId)
        .then((response) => {
          const temp = response.data
          this.list = this.stringToObject(temp)

          console.log(response)
          console.log(this.list)
        }) // 请求成功
        .catch((error) => {
          console.log(error)
        }) // 请求失败
    },

    // el-table要一个对象数组，你这里传入的是string数组，所以直接把string变成对象数组就行了
    stringToObject(stringArray) {
      const objectArray = []
      for (let i = 0; i < stringArray.length; i++) {
        objectArray.push({
          'TxId': stringArray[i]
        })
      }
      return objectArray
    }
  }
}
</script>

<style>
</style>
